<?php   // $Id: users_edit.php 279 2008-08-13 22:33:46Z pcoustillas $ ?>
<?php   
/*Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx
Modification : Pierre Coustillas*/

require_once("include/verif.php");
require_once("include/config/common.php");
require_once("include/language/$lang.php");
require_once("include/utils.php");
require_once("include/headers.php");

$num_user=isset($_GET['num_user'])?$_GET['num_user']:"";
$action=isset($_GET['action'])?$_GET['action']:"";


function yes_no_res($lecture_seul,$valeur)
{
	//premet juste une inclusion de code.
	?>
	<option value="n" <?php if ($valeur=="n") echo "selected='selected'" ?> >non</option>
	<option value="y" <?php if ($valeur=="y") echo "selected='selected'" ?> >oui</option>
	<?php
	/*if ($lecture_seul=="lecture_seul")
	{	
		?>
		<option value="r" <?php if ($valeur=="r") echo "selected='selected'" ?> >lecture seul</option>
		<?php
	}*/
}

?>

<script language="javascript" src="javascripts/verifier_form.js" type="text/javascript"></script>
<script type="text/javascript">
function verif_form()
{
	<?php if ($action=="modif") { //si modif d'un user il faut juste verifier que les mdp ne contiennent pas de carac spec ?>
		if (verifier('utilisateur','black','login2','vide#carac_spec','nom','vide','pass','carac_spec','pass2','carac_spec','mail','mail'))
	<?php } else {	//si new user il faut aussi verifier que les mdp ne soient pas vide ?>
		if (verifier('utilisateur','black','login2','vide#carac_spec','nom','vide','pass','vide#carac_spec','pass2','vide#carac_spec','mail','mail'))
	<?php } ?>
	{
		document.utilisateur.submit();
	} else {
		alert("<?php aff_lang('Une des valeurs saisie n\'est pas correct.\nMerci de corriger avant de poursuivre.') ?>")	
	}

}


</script>


<table width="760" border="0" class="page" align="center">
	<tr>
		<td class="page" align="center">
			<?php
			require_once("include/head.php");
			if ($action=="") 
			{
				echo "Erreur, pas d'action définie";
				//header("Location: lister_utilisateurs.php");
			}

			if (isset($_GET['msg']))
			{
				echo "<h2>" . $_GET['msg'] . "</h2>";
			}

			?>
		</td>
	</tr>
	<tr>
		<td class="page" align="center">
			<?php
				if ($user_admin != "y") { 
				echo "<h1>$lang_admin_droit</h1>";
				exit;
			}

			if ($action=="modif") 
			{
				//on selectionne l'utilisateur à modifier
				$sql = " SELECT * FROM " . $tblpref ."user WHERE num = $num_user ";
				$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
			
				$data = mysql_fetch_array($req);

				$login = $data['login'];
				$nom = $data['nom'];
				$prenom = $data['prenom'];
				$mail =$data['email'];
				$dev = $data['dev'];
				$com = $data['com'];
				$fact = $data['fact'];
				$dep = $data['dep'];
				$stat = $data['stat'];
				$art = $data['art'];
				$cli = $data['cli'];
				$admin = $data['admin'];

				$num_user = $data['num'];
			} else {
				//creation d'un nouveau utilisateur. Definition des valeurs par default
				$login="";
				$nom="";
				$prenom="";
				$mail="";
				$dev="n";
				$com="n";
				$fact="n";
				$dep="n";
				$stat="n";
				$art="n";
				$cli="n";
				$admin="n";
			}
			?>
		</td>	
	</tr>
	<form action="users_edit_suite.php" method="post" name="utilisateur">
	<tr>
		<td class="page" align="center">

			<table class="boiteaction">
				<caption>
				<?php 
					if ($action=="modif")
					{
						echo $lang_utilisateur_editer;
					} else {
						echo $lang_utilisateur_ajouter;
					}
				?>
				</caption>
				<tr> 
					<td class='<?php echo couleur_alternee (); ?>' id="login2">
						<?php echo $lang_utilisateur_nom; ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input type="text" <?php if ($action=="modif") echo "readonly='readonly'" ?> name="login2" value="<?php echo $login ?>" />
					</td>
				</tr>
				<tr> 
					<td class='<?php echo couleur_alternee (); ?>' id="nom">
						<?php echo $lang_nom; ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input name="nom" type="text" value="<?php   echo $nom ?>" />
					</td>
				</tr>
				<tr> 
					<td class='<?php echo couleur_alternee (); ?>' id="prenom">
						<?php echo $lang_prenom; ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input name="prenom" type="text"  value="<?php echo $prenom ?>" />
					</td>
				</tr>
				<tr> 
					<td class='<?php   echo couleur_alternee (); ?>' id="pass">
						<?php echo $lang_mot_de_passe; ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input name="pass" type="password" value="" />
					</td>
				</tr>
				<tr> 
					<td class='<?php echo couleur_alternee (); ?>' id="pass2">
						<?php echo $lang_mot_de_passe; ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input name="pass2" type="password" value="" />
					</td>
				</tr>
				<tr> 
					<td class='<?php echo couleur_alternee (); ?>' id="mail">
						<?php echo $lang_mail; ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input name="mail" type="text"  value="<?php echo $mail ?>"  />
					</td>
				</tr>
				<tr>
					<td class="submit" colspan="2">
						<?php echo $lang_util_droit?>
					</td>
				</tr>
				<tr> 
					<td class='<?php echo couleur_alternee (); ?>'>
						<?php echo $lang_ger_dev ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<select name ="dev">
							<?php yes_no_res("lecture_seul",$dev) ?>
						</select>
					</td>
				</tr>
						
				<tr>
					<td class='<?php echo couleur_alternee (); ?>'>
						<?php echo $lang_ger_com ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<select name ="com">
							<?php yes_no_res("lecture_seul",$com) ?>
						</select>
					</td>
				</tr>
				<tr>
					<td class='<?php echo couleur_alternee (); ?>'>
						<?php echo $lang_ger_fact ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<select name ="fact">
							<?php yes_no_res("lecture_seul",$fact) ?>
						</select>
					</td>
				</tr>
						
				<tr>
					<td class='<?php echo couleur_alternee (); ?>'>
						<?php echo $lang_ger_dep ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<select name ="dep">
							<?php yes_no_res("",$dep) ?>
						</select>
					</td>
				</tr>
						
				<tr>
					<td class='<?php   echo couleur_alternee (); ?>'>
						<?php   echo $lang_ger_stat ?>
					</td>
					<td class='<?php   echo couleur_alternee (FALSE); ?>'>
						<select name ="stat">
							<?php yes_no_res("",$stat) ?>
						</select>
					</td>
				</tr>
						
				<tr>
					<td class='<?php   echo couleur_alternee (); ?>'>
						<?php   echo $lang_ger_art ?>
					</td>
					<td class='<?php   echo couleur_alternee (FALSE); ?>'>
						<select name ="art">
							<?php yes_no_res("",$art) ?>
						</select>
					</td>
				</tr>
						
				<tr>
					<td class='<?php   echo couleur_alternee (); ?>'>
						<?php   echo $lang_ger_cli ?>
					</td>
					<td class='<?php   echo couleur_alternee (FALSE); ?>'>
						<select name ="cli">
							<?php yes_no_res("",$cli) ?>
						</select>
					</td>
				</tr>
						
				<tr>
					<td class='<?php   echo couleur_alternee (); ?>'>
						<?php echo $lang_dr_admi ?><br/>
						<?php echo $lang_admi_modu ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<select name ="admin" <?php if ($num_user == 1 ) { echo "disabled='disabled'" ;} ?> >
							<?php yes_no_res("",$admin) ?>
						</select>
					</td>
				</tr>
				<tr>
					<td class="submit" colspan="3">
						<input type="button" value="<?php echo $lang_envoyer; ?>" onclick="verif_form()"/> 
						<input type="hidden" name="action" value="<?php echo $action ?>" />
						<input type="hidden" name="num_user" value="<?php   echo $num_user ?>" /> 
						<input name="reset" type="reset" id="reset" value="<?php   echo $lang_effacer; ?>" /> 
					</td>
				</tr>
			</table>
		</td>
	</tr>
	
	</form>
	<tr>
		<td>
			<?php   
			require_once("include/bas.php");
			?>
		</td>
	</tr>

</table>



</body>

</html>
